package thread2;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class completableFutrue2 {

    public static void main(String[] args) {

        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            try {
                System.out.println(Thread.currentThread().getName());
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "hello";
        }).thenApplyAsync((str)->{
            System.out.println(Thread.currentThread().getName());
            System.out.println("receive:"+str);
            try {
                TimeUnit.SECONDS.sleep(2);

            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            };
            return  str + " world";
        }).thenApplyAsync((str)->{
            System.out.println(Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(2);

            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            };
            return  str + " .";
        });
        System.out.println("main exec");
        System.out.println(future.join());
        System.out.println("main end");
    }
}
